package fy.erp.operator;

import org.apache.commons.logging.LogFactory;

import com.seeyon.v3x.services.flow.bean.FlowExport;

import fy.erp.dao.NewClientDao;
import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.set.OA_UAPAccountContrast;
import fy.msg.MessageSender;
import fy.util.MyUtil;

public class NewClientOperator extends AForm_Save_Operator {
	private static org.apache.commons.logging.Log log = LogFactory
			.getLog(NewClientOperator.class);
	private static final String FORMNAME = "新客户授信申请表";
	private String clientName;
	private String clientCode;
	private String corp;
	private long memberID;
	private String number;

	public String getFormName() {
		return FORMNAME;
	}

	@Override
	protected void parseOtherField_FirstStep(FlowExport flowExport) {
		memberID = flowExport.getFlowCreatePerson().getId();
	}

	@Override
	protected void parseValueExport(com.seeyon.v3x.services.form.bean.ValueExport ve) {
		String name = ve.getDisplayName();
		String value = ve.getValue();
		if ("客户全称".equals(name)) {
			clientName = MyUtil.replaceXMLString(value);
		} else if ("客户编码".equals(name)) {
			clientCode = MyUtil.replaceXMLString(value).replace(" ", "");
		} else if ("单位选择器".equals(name)) {
			corp = OA_UAPAccountContrast.getUapAccountID(value);
		} else if ("单据编号".equals(name)) {
			number = value;
		}
		name = null;
		value = null;
	}

	@Override
	protected boolean save() {
		String msg = null;
		if (MyUtil.strIsNotNull(clientName) && MyUtil.strIsNotNull(clientCode)
				&& MyUtil.strIsNotNull(corp)) {
			NewClientDao dao = new NewClientDao();
			dao.setClientCode(clientCode);
			dao.setClientName(clientName);
			dao.setCorp(corp);
			dao.setNumber(number);
			return dao.save();
		} else {
			msg = "《新客户授信评审表单》数据导入ERP失败，";
		}
		MessageSender.sendMsg(memberID, msg);
		log.warn(msg);
		msg = null;
		clientName = null;
		clientCode = null;
		corp = null;
		return false;
	}

}
